<template>
  <view>
    <u-navbar is-back title="个人资料"></u-navbar>
    <u-card box-shadow="0rpx 0rpx 8px rgba(114, 118, 206, 0.2700)">
      <view slot="body">
        <u-form :model="user" ref="uForm">
          <u-form-item label="手机号" label-width="150">
            <u-input maxlength="13" v-model="user.phone"></u-input>
          </u-form-item>
          <u-form-item label="姓名" label-width="150">
            <u-input maxlength="10" v-model="user.name" placeholder="请输入"/>
          </u-form-item>
          <u-form-item label="学号" label-width="150">
            <u-input maxlength="10" v-model="user.stuNumber"/>
          </u-form-item>
          <u-form-item label="身份证" label-width="150">
            <u-input maxlength="18" v-model="user.idCard" placeholder="请输入"/>
          </u-form-item>
          <u-form-item label="学院" label-width="150">
            <u-input disabled @click="show=true" maxlength="10" v-model="user.college"/>
          </u-form-item>
          <u-form-item label="照片" label-width="150">
            <u-upload max-count="1" ref="image" :action="action" :auto-upload="true"
                      :file-list="images"></u-upload>
          </u-form-item>
        </u-form>
      </view>
    </u-card>
    <u-action-sheet @click="click" :list="list" v-model="show"></u-action-sheet>
    <u-button @click="submit" :custom-style="{'width':'30%'}">保存</u-button>
    <u-toast ref="uToast"/>

  </view>
</template>

<script>

import {getInfo} from "@/api/login";
import UButton from "@/uview-ui/components/u-button/u-button.vue";
import {updateUserProfile} from "@/api/system/user";
import {addCardInfo} from "@/api/card/cardInfo";
import config from "@/config";

export default {
  components: {UButton},
  data() {
    return {
      list: [
        {
          text: '智能制造',
        },
        {
          text: '电子工程与光电技术',
        },
        {
          text: '计算机与人工智能',
        }, {
          text: '商学院',
        }, {
          text: '人文与社会科学',
        }, {
          text: '智能控制',
        }
      ],
      show: false,
      action: config.baseUrl + '/common/upload',
      images: [],
      user: {}
    }
  },
  methods: {
    click(e) {
      this.user.college = this.list[e].text
    },
    submit() {
      this.images = this.$refs.image.lists.filter(val => {
        return val.progress == 100;
      })
      let urls = []
      for (let image of this.images) {
        urls.push(image.response.url)
      }
      this.user.avatar = urls[0]

      addCardInfo(this.user).then(response => {
        this.$refs.uToast.show({
          title: '保存成功',
          type: 'success',
        })
      })
    }
  },
  onLoad(options) {

  }
}
</script>

